/*
 * Copyright (C) GSX Techedu Inc. All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 */

package com.nime.novel.crawl.service.impl;

import com.nime.novel.crawl.constant.StatusEnum;
import com.nime.novel.crawl.domain.CrawlUrl;
import com.nime.novel.crawl.mapper.CrawlUrlMapper;
import com.nime.novel.crawl.service.CrawlUrlService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author liujialiang
 * @description
 * @team wuhan operational dev.
 * @date 2020/8/27 10:39 上午
 **/
@Slf4j
@Service
public class CrawlUrlServiceImpl implements CrawlUrlService {

    private final CrawlUrlMapper crawlUrlMapper;

    public CrawlUrlServiceImpl(CrawlUrlMapper crawlUrlMapper) {
        this.crawlUrlMapper = crawlUrlMapper;
    }

    @Override
    public CrawlUrl getById(Long id) {
        return crawlUrlMapper.getById(id);
    }

    @Override
    public CrawlUrl getOldCrawlUrlByStatus(Integer policyId, Integer channel,
        StatusEnum statusEnum) {
        return crawlUrlMapper.getOldUrlByStatus(policyId, channel, statusEnum.getCode());
    }

    public CrawlUrl getNewCrawlUrlByStatus(Integer policyId, Integer channel,
        StatusEnum statusEnum) {
        return crawlUrlMapper.getNewUrlByStatus(policyId, channel, statusEnum.getCode());
    }

    @Override
    public CrawlUrl getByUrlHash(String hash) {
        return crawlUrlMapper.findByUrlHash(hash);
    }

    @Override
    public int create(CrawlUrl url) {
        return crawlUrlMapper.create(url);
    }

    @Override
    public int updateStatus(Long id, Integer status) {
        return crawlUrlMapper.updateStatus(id, status);
    }

    @Override
    public void updateRoute(Long id, String route) {
        crawlUrlMapper.updateRoute(id, route);
    }
}
